﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Framework.Common.ConsistentHash
{

    /// <summary>
    /// Manager class to interface with the hashing and nodeSource locator class.
    /// </summary>
    public class SpaceMgr
    {
        public Node NodeSource = null;

        public Node Locate(string key)
        {
            return NodeLocator.Locate(NodeSource, key);
        }
        /// <summary>
        /// Initialize the space with a collection of nodes.
        /// </summary>
        /// <param name="nodes"> Collection of nodes</param>
        /// <param name="replicate"> number to replicate nodeSource</param>

        public SpaceMgr(IEnumerable<Node> nodes, int replicate)
        {
            NodeSource = new Node(nodes, replicate);
        }
        /// <summary>
        /// Initialize the space with a collection of nodes.
        /// </summary>
        /// <param name="nodes"> Collection of nodes</param>
        public SpaceMgr(IEnumerable<Node> nodes)
        {
            NodeSource = new Node(nodes);
        }

        /// <summary>
        /// Add a nodeSource in the nodeSource space
        /// </summary>
        /// <param name="node">a nodeSource to be added in the space.</param>
        public void Add(Node node)
        {
            NodeSource.Add(node);
        }

        /// <summary>
        /// Remove nodeSource from the space
        /// </summary>
        /// <param name="node">nodeSource to be removed</param>
        public void Remove(Node node)
        {
            NodeSource.Remove(node);
        }

    }
}
